package libs

import (
	"fmt"
	"reflect"
)

type User struct {
	Id   int
	Name string
	Age  int
}

func (u User) Call() {
	fmt.Println("user is called...")
	fmt.Printf("%v\n", u)
}

func DoFiledAndMethod(input any) {
	inputType := reflect.TypeOf(input)
	inputValue := reflect.ValueOf(input)

	fmt.Println("inputType is ", inputType.Name())
	fmt.Println("inputValue is ", inputValue)

	for i := 0; i < inputType.NumField(); i++ {
		field := inputType.Field(i)
		value := inputValue.Field(i).Interface()

		fmt.Printf("%s: %v = %v\n", field.Name, field.Type, value)
	}
}

func reflectNum(arg any) {
	fmt.Println("type: ", reflect.TypeOf(arg))
	fmt.Println("value: ", reflect.ValueOf(arg))
}

func ReflectShow() {
	// var num float64 = 1.23456
	// var tt string = "hello..."

	// reflectNum(num)
	// reflectNum(tt)

	user := User{1001, "张三", 22}
	DoFiledAndMethod(user)

}
